//
//  UITopLineButton.m
//  UICustomTextAlertView
//
//  Created by apple on 2018/2/7.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "UITopLineButton.h"

//线的高度
#define ksepeletorLineHeight  1

//按钮的高度
#define kButtonHeight  40

@interface UITopLineButton()

@property (nonatomic, strong) UIImageView *sepeletorLine;

@property (nonatomic, assign) CGFloat buttonHeight,lineHeight;
@end


@implementation UITopLineButton
- (instancetype)initWithButtonHeight:(CGFloat)buttonHeight  lineHeight:(CGFloat)lineHeight
{
    if(self = [super init])
    {
        self.buttonHeight = buttonHeight;
        self.lineHeight = lineHeight;
        if(self.buttonHeight == 0)
            self.buttonHeight = kButtonHeight;
        if(self.lineHeight == 0)
            self.lineHeight = ksepeletorLineHeight;
    }
    return self;
}


- (instancetype)initWithFrame:(CGRect)frame
{
    if(self = [super initWithFrame:frame])
    {
        [self addSubview:self.sepeletorLine];
        [self addSubview:self.button];
    }
    return self;
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    CGFloat width = self.bounds.size.width;
    self.sepeletorLine.frame = CGRectMake(0, 0, width, self.lineHeight);
    self.button.frame = CGRectMake(0, CGRectGetMaxY(self.sepeletorLine.frame), width, self.buttonHeight);
}




#pragma Mark-lazy

- (CGFloat)getTopLineButtonHieght
{
    return self.buttonHeight + self.lineHeight;
}
- (UIImageView *)sepeletorLine
{
    if(!_sepeletorLine){
        _sepeletorLine = [[UIImageView alloc]init];
        _sepeletorLine.backgroundColor = [UIColor grayColor];
        _sepeletorLine.contentMode = UIViewContentModeScaleAspectFill;
        _sepeletorLine.clipsToBounds = YES;
    }
    return _sepeletorLine;
}

- (UIButton *)button
{
    if(!_button){
        _button = [UIButton buttonWithType:UIButtonTypeCustom];
        [_button setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    }
    return _button;
}
@end
